package com.shujia.flink.tf;

import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

public class Demo1Map {
    public static void main(String[] args) throws Exception {
        //1、创建环境
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        //2、读取数据
        DataStream<String> studentDS = env.readTextFile("data/students/csv");

/*        DataStream<String> clazzDS = studentDS.map(new MapFunction<String, String>() {
         *//**
         * map方法每一条数据执行一次
         * @param line: 一行数据
         * @return ： 返回班级
         *//*
            @Override
            public String map(String line) throws Exception {
                String[] split = line.split("\\|");
                return split[4];
            }
        });*/

        //java 中的lambda表达式
        DataStream<String> clazzDS = studentDS.map(line -> line.split(",")[4]);


        clazzDS.print();

        env.execute();

    }
}
